<template>
    <div style="margin: 10px;">
        <van-cell-group>
            <template v-for="(value, key, index) in scenarios">
                <van-cell :title="value" :key="key" @click="toNew(key, value, index)" />
            </template>
        </van-cell-group>
    </div>
</template>
<script>
import Vue from 'vue'
import { Search, List, Cell, PullRefresh, Toast, Tabbar, TabbarItem, Popup } from 'vant'
import qs from 'qs'
Vue.use(Search).use(List).use(Cell).use(PullRefresh).use(Toast).use(Tabbar).use(TabbarItem).use(Popup)
export default {
    name: 'planscenario',
    data: function () {
        return {
            idtemplate: this.$route.query.idtemplate,
            scenarios: [],
            scenarioInfos: []
        }
    },
    created: function () {
        document.title = this.$route.query.stitle
    },
    mounted: function () {
        this.axios({
            method: 'post',
            url: '/api/scenario.getlist.do',
            data: qs.stringify({
            })
        }).then(res => {
            //console.log('scenario.getlist.do', res)
            this.scenarios = res.data.scenarios
            this.scenarioInfos = res.data.scenarioInfos
        }).catch(res => {
            this.reserror(res)
        })
    },
    methods: {
        toNew (scenarioid, scenariotitle, index) {
            this.$router.replace({
                name: 'plannew',
                query: {
                    stitle: '添加计划',
                    idobject: 'jhgl',
                    scenarioid: scenarioid,
                    scenariotitle: scenariotitle,
                    idtemplate: this.idtemplate,
                    routetype: '2c9a2d9291db5a1f0191dea23b4d00ec',
                    activeTab: '2c9a2d9291db5a1f0191de90efd70082',
                    scenarioInfo: JSON.stringify(this.scenarioInfos[scenarioid]),
                    code: this.$route.query.code,
                    mxlist: this.$route.query.mxlist
                }
            })
        }
    }
}
</script>
